<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>顾客信息</title>
<script src="../js/jquery-3.3.1.js"></script>
<script src="../layui/layui.js"></script>
<link rel="stylesheet" href="../layui/css/layui.css" /> 
<script src="../echartsjs/echarts.min.js"></script>
</head>
<body> 
<table id="tb" lay-filter="tbf"></table>
<script id="barDemo">
	<div class="layui-btn-container" > 
		<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="reset" >重置密码</button>
	</div>
</script>
<script>
layui.use('table',function(){
	var  table=layui.table;
	var laypage = layui.laypage;
	table.render({
		elem:"#tb", 
		url:"../client", 
		height:'313',
		page:{
			 layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
        ,curr: 1 //设定初始在第 5 页
        ,groups: 3//只显示 1 个连续页码
        ,first: false //不显示首页
        ,last:  false
		},
		limit:5,
		limits:[5,6,7,8,9,10],
		request:{
			pageName:'page',
			limitName:'pageSize'
		},
		cols:[[
			{field:'cid',title:"顾客id", sort: true},
			{field:'client',title:"顾客名称", sort: true},
			{field:'password',title:"密码",sort:true,}, 
			{field:'tool',title:"操作",align:"center",toolbar:"#barDemo"}
		]] 
	});
	table.on('tool(tbf)',function(obj){
		var data = obj.data; 
		console.log(obj);
		if (obj.event === 'reset') {
			layer.confirm("确认将顾客密码重置为123456嘛",{
				icon:0,
				title:'小贴士',
				offset:'150px'
			},function(index){
				$.ajax({
					url:"../client",
					method:"get", 
					data:{"type":"reset","cid":data.cid},
					success:function(data){   
						if(encode==1){
							alert("重置成功");
						}
					},
					dataType:'json'
				});
				alert("重置成功");
				//重新渲染
				table.render({
					elem:"#tb", 
					url:"../client", 
					height:'313',
					page:{
						 layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
			        ,curr: 1 //设定初始在第 5 页
			        ,groups: 3//只显示 1 个连续页码
			        ,first: false //不显示首页
			        ,last:  false
					},
					limit:6,
					request:{
						pageName:'page',
						limitName:'pageSize'
					},
					cols:[[
						{field:'cid',title:"顾客id", sort: true},
						{field:'client',title:"顾客名称", sort: true},
						{field:'password',title:"密码",sort:true,}, 
						{field:'tool',title:"操作",align:"center",toolbar:"#barDemo"}
					]] 
				});
				layer.closeAll('dialog'); 
			}) 
		} 
	});
})
</script>
</body>
</html>